package com.googlecode.bip.xml.export;

import java.sql.SQLException;
import java.util.List;
import javax.naming.NamingException;

/**
 *
 * @author Claude CHOISNET
 */
//not public
class XMLTopicLocalFactory
    extends XMLSurveyEntryFactoryBuilder<XMLTopicLocal>
{
    //private static final long serialVersionUID = 1L;

    protected XMLTopicLocalFactory(
            XMLSurveyConnection connection,
            String              sql
            )
    {
        super( connection, sql );
    }

    /**
     *
     * @param idtopic
     * @return
     * @throws SQLException
     * @throws NamingException
     */
    public static List<XMLTopicLocal> createList(
            XMLSurveyConnection connection,
            int                 idtopic
            )
        throws SQLException, NamingException
    {
        XMLTopicLocalFactory xml = new XMLTopicLocalFactory(
                connection,
                "SELECT * FROM `topics_local` WHERE `idtopic`=" + idtopic + ";"
                );
        //ResultSet rset = xml.execute();
        XMLSurveyConnection.ResultSetCache rset = xml.execute(
                "idlocal",
                "topicname",
                "topicdescription"
                );

        try {
            while( rset.next() ) {
                String local            = rset.getString( "idlocal" );
                String topicname        = rset.getString( "topicname" );
                String topicdescription = rset.getString( "topicdescription" );

                xml.add( new XMLTopicLocal( local, topicname, topicdescription ) );
                }
            }
        finally {
            rset.close();
            }

        return xml.getList();
    }

}
